package com.woniuxy.util;

import javax.naming.NameClassPair;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author: wgt
 * Date: 2021/11/9:21:54
 * Description:
 */
public class BeanFactory {

    private static Map <String,Object > map=new HashMap<>();
    static {
        Properties properties = new Properties();
        InputStream resourceAsStream = BeanFactory.class.getResourceAsStream("applicationContext.properties");
       String personName=null;
        try {
            properties.load(resourceAsStream);
            Set<Object> keys=properties.keySet();
            for (Object key:keys){
                //value
                personName=properties.getProperty(key+"");
                //把对应的k-v放入map集合中
                map.put(key+"",personName);
                String s = (String) map.get(key);
                Object val = Class.forName(s).newInstance();
                map.put((String) key,val);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }


    }



    public Object getBean(String name){
    return map.get(name);
    }
}
